/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author Bich Tran Van
 */
class ChangeColor extends JLabel implements TableCellRenderer {

    private String columnName1;
    private String columnName2;

    public ChangeColor(String column1, String column2) {
        this.columnName1 = column1;
        this.columnName2 = column2;
        setOpaque(true);
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
        Object columnValue1 = table.getValueAt(row, table.getColumnModel().getColumnIndex(columnName1));
        Object columnValue2 = table.getValueAt(row, table.getColumnModel().getColumnIndex(columnName2));
        if (value != null) {
            setText(value.toString());
        }
        setBackground(table.getBackground());
        setForeground(table.getForeground());
        String fine = String.valueOf(columnValue1);
        String status = String.valueOf(columnValue2);
        if (fine.equals("0.0")) {
        } else {
            if (status.equals("Unpaid")) {
                setBackground(Color.red);
            }
        }
        return this;
    }
}
